/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.helper;

import com.ivanbiz.dao.LockDateDAO;
import com.ivanbiz.dao.PenjualanDAO;
import com.ivanbiz.dao.impl.LockDateDAOImpl;
import com.ivanbiz.dao.impl.PenjualanDAOImpl;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class MyUniqueNumber {

    public String getNoTransaksi(){
        String noTransaksi = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        String prev = GlobalSession.getPreviousNoTransaksi();
        if(!"".equals(prev)){
            String[] splitPrev = prev.split("-");
            int count = Integer.parseInt(splitPrev[2]);
            count +=1;
            noTransaksi = GlobalSession.getNameCompany()+"-"+sdf.format(GlobalSession.getLockDate())+"-"+count;            
        }else{
            noTransaksi = GlobalSession.getNameCompany()+"-"+sdf.format(GlobalSession.getLockDate())+"-"+"1";            
        }       
        return noTransaksi;
    }
    public void setDateUniqueNumber(){
        LockDateDAO lockDateDAO = new LockDateDAOImpl();
        PenjualanDAO penjualanDAO = new PenjualanDAOImpl();
        try {
            Date date = lockDateDAO.getDateToday();
            String noTransaksi = penjualanDAO.getLastNoTransaksi();
            GlobalSession.setLockDate(date);
            GlobalSession.setPreviousNoTransaksi(noTransaksi);
        } catch (Exception ex) {
            Logger.getLogger(MyUniqueNumber.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
